home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Applications / Alpha.5.96 folder / Tcl / SystemCode / latex.tcl < prev    next >
Encoding:
Text File  |  1994-09-20  |  69.6 KB  |  2 lines  |  [TEXT/ALFA]

  1. ############################################################################################################################################################ latex.tcl, version 2.3:  macros and bindings for LaTeX users## -- see "LaTeX Help" and "LaTeX Key Bindings" on the Help menu# -- command summaries suitable for printing ("latex_commands.tex" #    and "latex_keys.tex") will be found in the LaTeX folder.################################################################################ version 1.1 and 1.2 (11/10/92) by Richard T. Austin (austin@eecs.umich.edu)# version 2.0--2.2 and 2.3 (9/15/94) by Tom Scavo (trscavo@syr.edu)## If you make improvements to this file, please share them!############################################################################################################################################################--------------------------------------------------------------------------# Autoload procedure:#--------------------------------------------------------------------------proc dummyTeX {} {}#--------------------------------------------------------------------------# Other macro packages:#--------------------------------------------------------------------------source "$HOME:Tcl:UserCode:smart.tcl"#--------------------------------------------------------------------------# Flags and Variables:#--------------------------------------------------------------------------set true 1set false 0# Flags:newModeVar TeX optionIsMeta $false 1newModeVar TeX useBoxMacro $true 1newModeVar TeX useDollarSigns $false 1newModeVar TeX searchNoisily $true 1newModeVar TeX promptNoisily $true 1newModeVar TeX deleteObjectNoisily $true 1newModeVar TeX deleteEnvironmentNoisily $true 1newModeVar TeX wordWrap $true 1newModeVar TeX useStatusBar $true 1# Variables:newModeVar TeX boxMacroName {BoxedEPSF} 0 newModeVar TeX funcExpr {\\((sub)*section|chapter)(\[.*\]|\*)?{([^{}]*)}} 0newModeVar TeX funcExprAlt {\\(section|chapter)(\[.*\]|\*)?{([^{}]*)}} 0 newModeVar TeX prefixString {% } 0newModeVar TeX wordBreak {(\\)?[a-zA-Z0-9]+} 0newModeVar TeX wordBreakPreface {([^a-zA-Z0-9\\]|.\\)} 0#--------------------------------------------------------------------------# Mark Menu:#--------------------------------------------------------------------------proc TeXMarkFile {} {    set end [maxPos]    set pos 0    set l {}    # Remove all previous marks in this file?    set exp {\\((sub)*section|chapter)(\[.*\]|\*)?{([^{}]*)}}    while {![catch {search -f 1 -r 1 -m 0 -i 0 $exp $pos} res]} {        set start [lindex $res 0]        set end [lindex $res 1]        set text [getText $start $end]        if {[regexp {\{(.*)\}} $text dummy mtch]} {            set lab ""            if {[regexp {(sub)*section} $text title]} then {                append lab $l [format "%[expr [string length $title] - 7]\s" ""]            } else {                set l {   }            }            append lab $mtch            setNamedMark $lab [lineStart [expr $start - 1]] $start $start        }        set pos [expr $end+1]    }}#--------------------------------------------------------------------------# Insertion routines:#--------------------------------------------------------------------------# Returns a modified text string if the string $text is non-null, # and the null string otherwise.  The argument 'operation' is a # string directing 'doPrefixText' to either "insert" or "remove" # $prefixString to/from each line of $text.  (This routine is# adapted from strings.tcl.)proc doPrefixText {operation prefixString text} {    if {$text == ""} {return ""}    set pref [quoteExpr $prefixString]    if {$operation == "insert"} then {        set trailChar ""        set textLen [string length $text]        if {[string index $text [expr $textLen-1]] == "\r"} then {            set text [string range $text 0 [expr $textLen-2]]            set trailChar "\r"        }        set str \r$prefixString        regsub -all \r $text $str text        return $prefixString$text$trailChar    } elseif {$operation == "remove"} then {        regsub -all \r$pref $text \r text        regsub ^$pref $text "" text        return $text    }}# Shift each line of $text to the right by inserting a string of# $whitespace characters at the beginning of each line, returning# the resulting string.proc shiftTextRight {text whitespace} {    return [doPrefixText "insert" $whitespace $text]}# Return a string of whitespace characters from the beginning # of the line containing $pos up to the first non-whitespace # character.proc getIndentation {pos} {    set text [getText [lineStart $pos] [nextLineStart $pos]]    regexp {^[ \t]*} $text theIndentation    return $theIndentation}# Return an "indented carriage return" if any character preceding # the insertion point (on the same line) is a non-whitespace # character.  Otherwise, return the null string.proc openingCarriageReturn {} {    set pos [getPos]    set end $pos    set start [lineStart $pos]    set text [getText $start $end]    if {[isWhitespace $text]} then {        if {$start == $end} {return [getIndentation $pos]} {return ""}    } else {        return "\r[getIndentation $pos]"    }}# Return an "indented carriage return" if any character following # the insertion point (on the same line) is a non-whitespace # character.  Otherwise, return the null string.proc closingCarriageReturn {} {    set pos [selEnd]    if {[isSelection] && ($pos == [lineStart $pos])} then {        return "\r"    } else {        set start $pos        set end [nextLineStart $start]        set text [getText $start $end]        if {[isWhitespace $text]} then {            return ""        } else {            return "\r[getIndentation $pos]"        }    }}# Insert an object at the insertion point. If there is a selection and the # global variable 'deleteObjectNoisily' is false, quietly delete the selection # first (just like 'paste'). Otherwise, prompt the user for the appropriate # action. Returns true if the object is ultimately inserted, and false if the # user cancels the operation. proc insertObject {objectName} {    global deleteObjectNoisily    if {[isSelection]} then {        if {$deleteObjectNoisily} then {            case [askyesno -c "Delete selection?"] in {                "yes" {deleteText [getPos] [selEnd]}                "no" {backwardChar}                "cancel" {return 0}            }        } else {            deleteText [getPos] [selEnd]        }    }    insertText $objectName    return 1}# Insert an object at the insertion point. If there is a selection, wrap # it inside the parameters $left and $right. Returns true if there is a # selection (in which case it will wrap), and false otherwise. proc wrapObject {left right} {    set currentPos [getPos]    set selected [isSelection]    if {$selected} then {        replaceText $currentPos [selEnd] $left [getSelect] $right    } else {        insertText $left "•" $right    }    goto $currentPos    nextTabStop    return $selected}# Builds and returns a LaTeX environment, that is, a \begin...\end # pair, given the name of the environment, an argument string, # and the environment body.  The body should be passed to this # procedure fully formatted, including indentation.proc buildEnvironment {envName envArg envBody trailingComment} {    set indent [getIndentation [getPos]]    set envStr [openingCarriageReturn]    append envStr "\\begin{" $envName "}"    append envStr $envArg "\r"    append envStr $envBody    append envStr $indent "\\end{" $envName "}$trailingComment"    append envStr [closingCarriageReturn]    return $envStr}# Inserts a LaTeX environment with the specified name, argument, # and body at the insertion point.  Positions the cursor at the # beginning of the environment, leaving any subsequent action to the # calling procedure.  Deletes the current selection quietly if the # global variable 'deleteEnvironmentNoisily' is false; otherwise # the user is prompted for directions.  Returns true if the # environment is ultimately inserted, and false if the user cancels # the operation.proc insertEnvironment {envName envArg envBody} {    global deleteEnvironmentNoisily    if {[isSelection]} then {        if {$deleteEnvironmentNoisily} then {            case [askyesno -c "Delete selection?"] in {                "yes" {}                "no" {backwardChar}                "cancel" {return 0}            }        }    }    set start [getPos]    set end [selEnd]    set body [shiftTextRight $envBody [getIndentation $start]]    replaceText $start $end [buildEnvironment $envName $envArg $body "•"]    goto $start    return 1}# Inserts an environment with the given name, argument, and body at # the insertion point.  Positions the cursor at the beginning of # the environment, leaving any subsequent action to the calling # procedure.  If there is currently a selection, cut and paste it # into the body of the new environment, maintaining proper # indentation; otherwise, insert a tab stop into the body of the# environment.  Returns true if there is a selection, and false # otherwise.proc wrapEnvironment {envName envArg envBody} {    set start [getPos]    set end [selEnd]    set indent [getIndentation $start]    if {[isSelection]} then {        set text [getSelect]        set textLen [string length $text]        if {[string index $text [expr $textLen-1]] != "\r"} then {            append text "\r"        }        if {$start == [lineStart $start]} then {            set body [shiftTextRight $text \t]        } else {            set body "$indent[shiftTextRight $text \t]"        }        append body [shiftTextRight $envBody $indent]        set environment [buildEnvironment $envName $envArg $body "•"]        set returnFlag 1    } else {        append body "$indent\t•\r" [shiftTextRight $envBody $indent]        set environment [buildEnvironment $envName $envArg $body "•"]        set returnFlag 0    }    replaceText $start $end $environment    goto $start    return $returnFlag}# A generic call to 'wrapEnvironment' used throughout latex.tcl:proc doWrapEnvironment {envName} {    if {[wrapEnvironment $envName "" ""]} then {        set msgText "selection wrapped"    } else {        set msgText "enter body of $envName environment"    }    nextTabStop    message $msgText}# Inserts a structured document template at the insertion point.  # Three arguments are required:  the class name of the document, a # preamble string, and a string containing the body of the document.  # If the preamble is null, a generic \usepackage statement is # inserted; otherwise, the preamble is inserted as is.  This routine # does absolutely no error-checking (this is totally left up to the # calling procedure) and returns nothing.proc insertDocument {className preamble docBody} {    set docStr "\\documentclass\[•\]{$className}\r"    if {$preamble == ""} then {        append docStr "\\usepackage{•}\r\r•\r\r"    } else {        append docStr $preamble    }    append docStr [buildEnvironment "document" "" $docBody "\r"]    set start [getPos]    set end [selEnd]    replaceText $start $end $docStr    goto $start    return}# Inserts a document template at the insertion point given the # class name of the document to be inserted.  If ALL of the current# document is selected, then the routine wraps the text inside a# generic document template.  If the file is empty, a bullet is # inserted in place of the document body.  If neither of these # conditions is true, an alert is displayed, and no action is taken.  # Returns true if wrapping occurs, and false otherwise.proc wrapDocument {className} {    if {[isEmptyFile]} then {        append body "\r•\r\r"        set returnFlag 0    } else {        if {[isDocumentSelected]} then {            set text [getSelect]            append body "\r$text\r"            set returnFlag 1        } else {            alertnote "nonempty file:  delete text or \'Select All\'\                from the Edit menu"            return 0        }    }    set docStr "\\documentclass\[•\]{$className}\r"    append docStr "\\usepackage{•}\r\r•\r\r"    append docStr [buildEnvironment "document" "" $body "\r"]    set start [getPos]    set end [selEnd]    replaceText $start $end $docStr    goto $start    nextTabStop    message "enter style (or leave blank)"    return $returnFlag}#--------------------------------------------------------------------------# Misc:#--------------------------------------------------------------------------# Checks to see if there's a current selection.proc isSelection {} {    return [string length [getSelect]]}# Checks to see if the current window is empty, sans whitespace.proc isEmptyFile {} {    return [isWhitespace [getText 0 [maxPos]]]}# If there is a selection, make sure it's uppercase.  Otherwise, # check to see if the character after the insertion point is uppercase.proc isUppercase {} {    if {[isSelection]} then {        set text [getSelect]    } else {        set text [lookAt [getPos]]    }    return [expr {[string toupper $text] == $text}]}# Returns true if the entire window is selected, and false otherwise.proc isDocumentSelected {} {    return [expr {([getPos] == 0) && ([selEnd] == [maxPos])}]}# Takes any string and tests whether or not that string contains all # whitespace characters.  Carriage returns are considered whitespace, # as are spaces and tabs.  Also returns true for the null string.proc isWhitespace {anyString} {    set len [string length $anyString]    for {set i 0} {$i < $len} {incr i} {        set c [string index $anyString $i]        if {($c != "\ ") && ($c != "\t") && ($c != "\r")} then {return 0}    }    return 1}# Select the line containing the insertion point.proc lineSelect {} {    goto [lineStart [getPos]]    nextLineSelect}# Check to see if the LaTeX symbol package has been loaded; if not, ask # the user for directions.  Returns false if the package is not loaded# AND the user cancels the operation; otherwise, returns true.proc isSymbolPackageLoaded {} {    global searchNoisily    set begPos [getPos]    set endPos [selEnd]    set searchString {\\usepackage\{.*latexsym.*\}}    set searchResult [search -n -f 0 -m 0 -i 1 -r 1 $searchString $begPos]    if {[llength $searchResult] == 0} then {        case [askyesno -c "Insert the LaTeX symbol package?"] in {            "yes" {                set searchString {\\documentclass(\[.*\])?\{.*\}}                set searchResult [search -n -f 0 -m 0 -i 1 -r 1 $searchString $begPos]                if {[llength $searchResult] == 0} then {                    set returnVal 0                    if {$searchNoisily} {beep}                    message "can't find \\documentclass"                } else {                    goto [lindex $searchResult 1]                    set txt "\r\\usepackage\{latexsym\}"                    set offset [string length $txt]                    set begPos [expr $begPos + $offset]                    set endPos [expr $endPos + $offset]                    insertText $txt                    set returnVal 1                }            }            "no" {set returnVal 1}            "cancel" {set returnVal 0}        }    } else {        set returnVal 1    }    select $begPos $endPos    return $returnVal}############################################################################## # Basic Commands##############################################################################proc typeset {} {    global latexPath        # Initialization:    set isOzTeX 0    set isTextures 0    set isCMacTeX 0        set currentWin [lindex [winNames -f] 0]        # Check if a LaTeX app is running.  If not, open the app named in     # $latexPath (if defined) or have the user select an app via a    # standard file dialog.    set appName [checkRunningL LaTeX {OTEX *TEX *XeT} latexPath]        if {[string match {OzTeX*} $appName]} {        set isOzTeX 1    } elseif {[string match {Textures*} $appName]} {        set isTextures 1    } elseif {[string match {*tex} $appName]} {        set isCMacTeX 1    } else {        alertnote "Sorry, I don't know how to talk to \"$appName\"."        return    }    if {[winInfo dirty]} {        case [askyesno -c "Save \"$currentWin\"?"] in {            "yes" {save}            "no" {}            "cancel" {return}        }    }    switchTo $appName    if {$isOzTeX} {        sendOpenEvent -n $appName $currentWin    } elseif {$isTextures} {        sendOpenEvent -n $appName $currentWin    } elseif {$isCMacTeX} {        dosc -n $name -k 'aevt' -e 'odoc' -r -f $currentWin    }}# Slightly modified version of 'checkRunning' that looks for any of a# list of running apps.  (Courtesy of Tom Pollard)proc checkRunningL {prompt sigs path} {    global $path    foreach sig $sigs {        foreach proc [processes] {            if {[lindex $proc 1] == $sig} {                return [lindex $proc 0]            }        }    }    if {![info exists $path] || ![file exists [set $path]]} {        if {[addAppPath $prompt $path]} return    }    if {[catch {getFileSig [set $path]}]} {        if {[addAppPath $prompt $path]} return    }    set sig [getFileSig [set $path]]    if {[catch {launch -f [set $path]}]} {        error "Problem with launching file (out of memory?)"    }    return [file tail [set $path]]#    return [checkRunning $name $sig $path]}#--------------------------------------------------------------------------# Goto:#--------------------------------------------------------------------------# Switch to (but don't execute) any of the following applications.proc latex {} {    global latexPath    set sig ""    catch {string trim [lindex [getfinfo $latexPath] 1] '} sig    set name [checkRunning latex $sig latexPath]    if {![string length $name]} return    switchTo $name}proc bibtex {} {    global bibtexPath    set name [checkRunning BibTeX BIBt bibtexPath]    if {![string length $name]} return    switchTo $name}proc makeindex {} {    global makeindexPath    set name [checkRunning MakeIndex Midx makeindexPath]    if {![string length $name]} return    switchTo $name}proc nextSection {} {    global searchNoisily funcExprAlt    set searchString $funcExprAlt    if {[isSelection]} then {        set searchPos [expr [getPos]+1]    } else {        set searchPos [getPos]    }    set searchResult [search -f 1 -r 1 -n $searchString $searchPos]    if {[string length $searchResult]} {        select [lindex $searchResult 0] [lindex $searchResult 1]    } else {        if {$searchNoisily} {beep}        message "next $funcExprAlt not found"    }}proc prevSection {} {    global searchNoisily funcExprAlt    set searchString $funcExprAlt    set searchResult [search -f 0 -r 1 -n $searchString [expr [getPos]-1]]    if {[string length $searchResult]} {        select [lindex $searchResult 0] [lindex $searchResult 1]    } else {        if {$searchNoisily} {beep}        message "previous $funcExprAlt not found"    }}proc nextSubsection {} {    global searchNoisily funcExpr    set searchString $funcExpr    if {[isSelection]} then {        set searchPos [expr [getPos]+1]    } else {        set searchPos [getPos]    }    set searchResult [search -f 1 -r 1 -n $searchString $searchPos]    if {[string length $searchResult]} {        select [lindex $searchResult 0] [lindex $searchResult 1]    } else {        if {$searchNoisily} {beep}        message "next $funcExpr not found"    }}proc prevSubsection {} {    global searchNoisily funcExpr    set searchString $funcExpr    set searchResult [search -f 0 -r 1 -n $searchString [expr [getPos]-1]]    if {[string length $searchResult]} {        select [lindex $searchResult 0] [lindex $searchResult 1]    } else {        if {$searchNoisily} {beep}        message "previous $funcExpr not found"    }}proc gotoTabStop {directionIndicator} {    set searchResult [search -n -f $directionIndicator -m 0 -i 1 -r 0 {•} [getPos]]    if {[llength $searchResult] == 0} then {        return 0    } else {        goto [lindex $searchResult 0]        return 1    }}proc nextTabStop {} {    global searchNoisily    set forward 1    if {[gotoTabStop $forward]} then {        deleteChar    } else {        if {$searchNoisily} {beep}        message "tab stop not found"    }}proc prevTabStop {} {    global searchNoisily    set forward 0    if {[gotoTabStop $forward]} then {        deleteChar    } else {        if {$searchNoisily} {beep}        message "tab stop not found"    }}proc nthTabStop {numTabStops} {    global searchNoisily promptNoisily useStatusBar    if {$numTabStops == 0} then {        if {$promptNoisily && $useStatusBar} {beep}        catch {sPrompt "How many tab stops?" "3"} numTabStops        if {$numTabStops == "cancel"} then {            return        }    }    set currentPos [getPos]    if {$numTabStops > 0} {set forward 1} {set forward 0}    set maxits [expr abs($numTabStops)]    if {![gotoTabStop $forward]} then {        if {$searchNoisily} {beep}        message "tab stop not found"        goto $currentPos        return    }    for {set i 1} {$i < $maxits} {incr i} {        if {$forward} {forwardChar} {backwardChar}        if {![gotoTabStop $forward]} then {            if {$searchNoisily} {beep}            message "tab stop not found"            goto $currentPos            return        }    }    deleteChar}#--------------------------------------------------------------------------# Utilities:#--------------------------------------------------------------------------proc clearTabStops {} {    global searchNoisily    message "working..."    set messageString "selection"    if {[set start [getPos]] == [set end [selEnd]]} {        set messageString "document"        set start 0        set end [maxPos]    }    set text [getText $start $end]    if {[regsub -all {•} $text {} text]} then {        replaceText $start $end $text        set end [getPos]        select $start $end        message "tab stops removed from $messageString"    } else {        if {$searchNoisily} {beep}        message "no tab stops found in $messageString"    }}proc convertDollarSigns {} {    global searchNoisily    message "working..."    set messageString "selection"    if {[set start [getPos]] == [set end [selEnd]]} {        set messageString "document"        set start 0        set end [maxPos]    }    set text [getText $start $end]    # Convert all displaymath mode:    set convert1 [regsub -all {\$\$([^$]*)\$\$} $text {\\[\1\\]} text]    # Convert all math mode:    set convert2 [regsub -all {\$([^$]*)\$} $text {\\(\1\\)} text]    if {$convert1 || $convert2} then {        replaceText $start $end $text        message "$messageString converted to LaTeX math mode format"    } else {        if {$searchNoisily} {beep}        message "no dollar signs found in $messageString"    }}proc loadSymbolPackage {} {    global searchNoisily    set begPos [getPos]    set endPos [selEnd]    set searchString {\\usepackage\{.*latexsym.*\}}    set searchResult [search -n -f 1 -m 0 -i 1 -r 1 $searchString 0]    if {[llength $searchResult] == 0} then {        set searchString {\\documentclass(\[.*\])?\{.*\}}        set searchResult [search -n -f 1 -m 0 -i 1 -r 1 $searchString 0]        if {[llength $searchResult] == 0} then {            if {$searchNoisily} {beep}            message "can't find \\documentclass"        } else {            goto [lindex $searchResult 1]            set txt "\r\\usepackage\{latexsym\}"            set offset [string length $txt]            set begPos [expr $begPos + $offset]            set endPos [expr $endPos + $offset]            insertText $txt        }    } else {        if {$searchNoisily} {beep}        select $begPos $endPos        message "symbol package already loaded"    }}############################################################################## # Paragraph Mode Macros###############################################################################--------------------------------------------------------------------------# Documents:#--------------------------------------------------------------------------proc letter {} {    set    preamble "\r\\address\{%\r"    append preamble "    •    \\\\    % insert your name here\r"    append preamble "    •    \\\\    % insert your address here\r"    append preamble "    •    \\\\    % insert more address here\r"    append preamble "    •          % insert city-state-zip here\r"    append preamble "\}\r\r"    append preamble "\\date\{•\}  % optional\r"    append preamble "\\signature\{•\}\r\r"    set    body "\r\\begin\{letter\}\{%\r"    append body "    •    \\\\    % insert addressee's name here\r"    append body "    •    \\\\    % insert addressee's address here\r"    append body "    •    \\\\    % insert more address here\r"    append body "    •          % insert addressee's city-state-zip here\r"    append body "\}\r\r"    append body "\\opening\{Dear •,\}\r\r"    if {[isEmptyFile]} then {        append body "% BODY OF LETTER\r"        append body "•\r\r"    } else {        if {[isDocumentSelected]} then {            set text [getSelect]#             deleteText 0 [maxPos]            append body "$text\r"        } else {            alertnote "nonempty file:  delete text or \'Select All\'\                from the Edit menu"            return        }    }    append body "\\closing\{Sincerely,\}\r\r"    append body "\\encl\{•\}\r"    append body "\\cc\{•\}\r\r"    append body "\\end\{letter\}\r\r"    insertDocument "letter" $preamble $body    nextTabStop    message "enter style (or leave blank)"}proc article {} {    wrapDocument "article"}proc report {} {    wrapDocument "report"}proc book {} {    wrapDocument "book"}proc slides {} {    wrapDocument "slides"}proc custom {} {    catch {prompt "What documentclass?" "article"} documentType    if {$documentType != "cancel"} then {        wrapDocument "$documentType"     }}proc getStyle {} {    catch {prompt "Choose a style:" "11pt" "" "11pt" "12pt" "titlepage" \                  "twocolumn" "twoside" "a4paper" "leqno" "fleqn"} styleName    if {$styleName != "cancel"} then {        return $styleName    } else {        return ""    }}proc insertStyle {style} {    global searchNoisily    set searchString {\\documentclass}    set searchResult [search -n -f 1 -m 0 -i 1 -r 1 $searchString 0]    if {[llength $searchResult] == 0} then {        if {$searchNoisily} {beep}        message "can\'t find \\documentclass"    } else {        set nextCharPos [lindex $searchResult 1]        goto $nextCharPos        set nextChar [lookAt $nextCharPos]        if {$nextChar == "\["} then {            forwardChar            insertText $style            if {[lookAt [getPos]] != "\]"} then {                insertText ","            }        } elseif {$nextChar == "\{"} then {            insertText "\[$style\]"        } else {            alertnote "unrecognizable \\documentclass statement"        }    }}proc styles {} {    set style [getStyle]    if {$style != ""} then {        insertStyle $style    }}proc getPackage {} {    catch {prompt "Choose a package:" "latexsym" "" "amstex" "babel" \                  "color" "graphics" "ifthen" "latexsym" "makeidx" \                  "showidx"} packageName    if {$packageName != "cancel"} then {        return $packageName    } else {        return ""    }}proc insertPackage {package} {    global searchNoisily    set searchString {\\documentclass(\[.*\])?\{.*\}}    set searchResult [search -n -f 1 -m 0 -i 1 -r 1 $searchString 0]    if {[llength $searchResult] == 0} then {        if {$searchNoisily} {beep}        message "can\'t find \\documentclass"    } else {        goto [lindex $searchResult 1]        insertText "\r\\usepackage\{$package\}"    }}proc packages {} {    set package [getPackage]    if {$package != ""} then {        insertPackage $package    }}proc filecontents {} {    global searchNoisily    set searchString {\\documentclass}    set searchResult [search -n -f 1 -m 0 -i 1 -r 1 $searchString 0]    if {[llength $searchResult] == 0} then {        if {$searchNoisily} {beep}        message "can\'t find \\documentclass"        return    } else {        set prompt "File to be included:"        if {[catch {getfile $prompt} path]} then {            return        } else {            set fd [open $path]            set text [read $fd]            close $fd            regsub -all {
  2. } $text \r text            goto 0            set envName "filecontents"            set envArg "{[file tail $path]}"            replaceText 0 0 [buildEnvironment $envName $envArg "$text\r" "\r\r"]            goto 0            message "file included"        }    }}#--------------------------------------------------------------------------# Page Layout:#--------------------------------------------------------------------------proc maketitle {} {    global searchNoisily    set searchString {\\document(class|style)(\[.*\])?\{.*\}}    set searchResult [search -n -f 1 -m 0 -i 1 -r 1 $searchString 0]    if {[llength $searchResult] == 0} then {        if {$searchNoisily} {beep}        message "can\'t find \\documentclass or \\documentstyle"    } else {        set searchPos [lindex $searchResult 1]        set searchString {\\begin\{document\}}        set searchResult [search -n -f 1 -m 0 -i 1 -r 1 $searchString $searchPos]        if {[llength $searchResult] == 0} then {            if {$searchNoisily} {beep}            message "can\'t find \\begin\{document\}"        } else {            goto [lindex $searchResult 1]            set currentPos [getPos]            set txt "\r\r% Definition of title page:"            append txt "\r\\title\{"            append txt "\r\t•\r\}"            append txt "\r\\author\{"            append txt "\r\t•\t% insert author(s) here"            append txt "\r\}"            append txt "\r\\date\{•\}\t% optional"            append txt "\r\r\\maketitle"            insertText $txt            goto $currentPos            nextTabStop            message "insert title"        }    }}proc abstract {} { doWrapEnvironment "abstract" }proc titlepage {} { doWrapEnvironment "titlepage" }proc getPagestyle {} {    catch {prompt "Choose a pagestyle:" "plain" "" "plain" "empty" \                  "headings" "myheadings"} pagestyleName    if {$pagestyleName != "cancel"} then {        return $pagestyleName    } else {        return ""    }}proc pagestyle {} {    set pagestyleName [getPagestyle]    if {$pagestyleName != ""} then {        openingCarriageReturn        insertObject "\\pagestyle\{$pagestyleName\}"        closingCarriageReturn    }}proc thispagestyle {} {    set pagestyleName [getPagestyle]    if {$pagestyleName != ""} then {        openingCarriageReturn        insertObject "\\thispagestyle\{$pagestyleName\}"        closingCarriageReturn    }}proc getPagenumberingStyle {} {    catch {prompt "Choose a pagenumbering style:" "arabic" "" "arabic" \                  "roman" "Roman" "alph" "Alph"} pagenumberingStyle    if {$pagenumberingStyle != "cancel"} then {        return $pagenumberingStyle    } else {        return ""    }}proc pagenumbering {} {    set pagenumberingStyle [getPagenumberingStyle]    if {$pagenumberingStyle != ""} then {        openingCarriageReturn        insertObject "\\pagenumbering\{$pagenumberingStyle\}"        closingCarriageReturn    }}proc twocolumn {} {    openingCarriageReturn    insertObject "\\twocolumn"    closingCarriageReturn}proc onecolumn {} {    openingCarriageReturn    insertObject "\\onecolumn"    closingCarriageReturn}#--------------------------------------------------------------------------# Sectioning:#--------------------------------------------------------------------------proc part {} {    if {[wrapObject "\\part{" "}•"]} then {        message "don't forget the label"    } else {        message "type the part name and don't forget the label"    }}proc chapter {} {    if {[wrapObject "\\chapter{" "}•"]} then {        message "don't forget the label"    } else {        message "type the chapter name and don't forget the label"    }}proc section {} {    if {[wrapObject "\\section{" "}•"]} then {        message "don't forget the label"    } else {        message "type the section name and don't forget the label"    }}proc subsection {} {    if {[wrapObject "\\subsection{" "}•"]} then {        message "don't forget the label"    } else {        message "type the subsection name and don't forget the label"    }}proc subsubsection {} {    if {[wrapObject "\\subsubsection{" "}•"]} then {        message "don't forget the label"    } else {        message "type the subsubsection name and don't forget the label"    }}proc paragraph {} {    if {[wrapObject "\\paragraph{" "}•"]} then {        message "don't forget the label"    } else {        message "type the paragraph name and don't forget the label"    }}proc subparagraph {} {    if {[wrapObject "\\subparagraph{" "}•"]} then {        message "don't forget the label"    } else {        message "type the subparagraph name and don't forget the label"    }}proc appendix {} {insertObject "\\appendix"}#--------------------------------------------------------------------------# Text Style:#--------------------------------------------------------------------------proc emph {} {    if {[wrapObject "\\emph{" "}•"]} then {        message "selected text is emphasized"    } else {        message "enter text to be emphasized"    }}proc textup {} {    if {[wrapObject "\\textup{" "}•"]} then {        message "selected text has upright shape"    } else {        message "enter text to have upright shape"    }}proc textit {} {    if {[wrapObject "\\textit{" "}•"]} then {        message "selected text has italic shape"    } else {        message "enter text to have italic shape"    }}proc textsl {} {    if {[wrapObject "\\textsl{" "}•"]} then {        message "selected text has slanted shape"    } else {        message "enter text to have slanted shape"    }}proc textsc {} {    if {[wrapObject "\\textsc{" "}•"]} then {        message "selected text has small caps shape"    } else {        message "enter text to have small caps shape"    }}proc textmd {} {    if {[wrapObject "\\textmd{" "}•"]} then {        message "selected text has been set in medium series"    } else {        message "enter text to be set in medium series"    }}proc textbf {} {    if {[wrapObject "\\textbf{" "}•"]} then {        message "selected text has been set in bold series"    } else {        message "enter text to be set in bold series"    }}proc textrm {} {    if {[wrapObject "\\textrm{" "}•"]} then {        message "selected text has been set with roman family"    } else {        message "enter text to be set using roman family"    }}proc textsf {} {    if {[wrapObject "\\textsf{" "}•"]} then {        message "selected text has been set with sans serif family"    } else {        message "enter text to be set using sans serif family"    }}proc texttt {} {    if {[wrapObject "\\texttt{" "}•"]} then {        message "selected text has been set with typewriter family"    } else {        message "enter text to be set using typewriter family"    }}proc textnormal {} {    if {[wrapObject "\\textnormal{" "}•"]} then {        message "selected text has been set with normal style"    } else {        message "enter text to be set using normal style"    }}#--------------------------------------------------------------------------# Text Size:#--------------------------------------------------------------------------proc tiny {} {    if {[wrapObject "{\\tiny " "}•"]} then {        message "tiny text set"    } else {        message "enter tiny text"    }}proc scriptsize {} {    if {[wrapObject "{\\scriptsize " "}•"]} then {        message "scriptsize text set"    } else {        message "enter scriptsize text"    }}proc footnotesize {} {    if {[wrapObject "{\\footnotesize " "}•"]} then {        message "footnotesize text set"    } else {        message "enter footnotesize text"    }}proc small {} {    if {[wrapObject "{\\small " "}•"]} then {        message "small text set"    } else {        message "enter small text"    }}proc normalsize {} {    if {[wrapObject "{\\normalsize " "}•"]} then {        message "normalsize text set"    } else {        message "enter normalsize text"    }}proc large {} {    if {[wrapObject "{\\large " "}•"]} then {        message "large text set"    } else {        message "enter large text"    }}proc Large {} {    if {[wrapObject "{\\Large " "}•"]} then {        message "Large text set"    } else {        message "enter Large text"    }}proc LARGE {} {    if {[wrapObject "{\\LARGE " "}•"]} then {        message "LARGE text set"    } else {        message "enter LARGE text"    }}proc huge {} {    if {[wrapObject "{\\huge " "}•"]} then {        message "huge text set"    } else {        message "enter huge text"    }}proc Huge {} {    if {[wrapObject "{\\Huge " "}•"]} then {        message "Huge text set"    } else {        message "enter Huge text"    }}#--------------------------------------------------------------------------# International:#--------------------------------------------------------------------------proc {ò} {} {    if {[wrapObject "\\`{" "}•"]} then {        message "accent set"    } else {        message "enter single character"    }}proc {ó} {} {    if {[wrapObject "\\'{" "}•"]} then {        message "accent set"    } else {        message "enter single character"    }}proc {ô} {} {    if {[wrapObject "\\^{" "}•"]} then {        message "accent set"    } else {        message "enter single character"    }}proc {ö} {} {    if {[wrapObject "\\\"{" "}•"]} then {        message "accent set"    } else {        message "enter single character"    }}proc {õ} {} {    if {[wrapObject "\\~{" "}•"]} then {        message "accent set"    } else {        message "enter single character"    }}proc {ç} {} {    if {[wrapObject "\\c{" "}•"]} then {        message "accent set"    } else {        message "enter single character"    }}proc {œ} {} {insertObject "\\oe"}proc {Œ} {} {insertObject "\\OE"}proc {æ} {} {insertObject "\\ae"}proc {Æ} {} {insertObject "\\AE"}proc {å} {} {insertObject "\\aa"}proc {Å} {} {insertObject "\\AA"}proc {ø} {} {insertObject "\\o"}proc {Ø} {} {insertObject "\\O"}proc {ß} {} {insertObject "\\ss"}proc {¿} {} {insertObject "?`"}proc {¡} {} {insertObject "!`"}#--------------------------------------------------------------------------# Environments:#--------------------------------------------------------------------------proc enumerate {} {    global promptNoisily useStatusBar    set envName "enumerate"    if {$promptNoisily && $useStatusBar} {beep}    catch {sPrompt "$envName:  how many items?" 3} numberItems    if {$numberItems != "cancel"} then {        set body "\t\\item  •"        for {set i 1} {$i < $numberItems} {incr i} {            append body "\r\r\t\\item  •"        }        append body "\r"        if {[insertEnvironment $envName "" $body]} then {            nextTabStop            message "type first item"        }    }}proc itemize {} {    global promptNoisily useStatusBar    set envName "itemize"    if {$promptNoisily && $useStatusBar} {beep}    catch {sPrompt "$envName:  how many items?" 3} numberItems    if {$numberItems != "cancel"} then {        set body "\t\\item  •"        for {set i 1} {$i < $numberItems} {incr i} {            append body "\r\r\t\\item  •"        }        append body "\r"        if {[insertEnvironment $envName "" $body]} then {            nextTabStop            message "type first item"        }    }}proc description {} {    global promptNoisily useStatusBar    set envName "description"    if {$promptNoisily && $useStatusBar} {beep}    catch {sPrompt "$envName: how many items?" 3} numberItems    if {$numberItems != "cancel"} then {        set body "\t\\item\[•\]  •"        for {set i 1} {$i < $numberItems} {incr i} {            append body "\r\r\t\\item\[•\]  •"        }        append body "\r"        if {[insertEnvironment $envName "" $body]} then {            nextTabStop            message "type first item label"        }    }}proc thebibliography {} {    global promptNoisily useStatusBar    set envName "thebibliography"    if {$promptNoisily && $useStatusBar} {beep}    catch {sPrompt "$envName:  how many bibitems?" 3} numberItems    if {$numberItems != "cancel"} then {        set arg "{99}"        set body "\t\\bibitem{•}\r\t•"        for {set i 1} {$i < $numberItems} {incr i} {            append body "\r\r\t\\bibitem{•}\r\t•"        }        append body "\r"        if {[insertEnvironment $envName $arg $body]} then {            nextTabStop            message "type first bibitem key"        }    }}proc slide {} { doWrapEnvironment "slide" }proc overlay {} { doWrapEnvironment "overlay" }proc note {} { doWrapEnvironment "titlepage" }proc figure {} {    global useBoxMacro boxMacroName    set envName "figure"    set arg "\[tbp\]"    if {$useBoxMacro} then {        set body "\t\\centerline{\\$boxMacroName{•}}\r"    }    append body "\t\\caption{•}\r"    append body "\t\\protect\\label{•}\r"    if {$useBoxMacro} then {        if {[insertEnvironment $envName $arg $body]} then {            set msgText "enter filename"        } else {            return        }    } else {        if {[wrapEnvironment $envName $arg $body]} then {            set msgText "enter caption"        } else {            set msgText "enter body of $envName environment"        }    }    nextTabStop    message $msgText}proc table {} {    set envName "table"    set arg "\[tbp\]"    append body "\t\\caption{•}\r"    append body "\t\\protect\\label{•}\r"    if {[wrapEnvironment $envName $arg $body]} then {        set msgText "enter caption"    } else {        set msgText "enter body of $envName environment"    }    nextTabStop    message $msgText}proc buildRow {jmax} {    set txt "•"    for {set j 1} {$j < $jmax} {incr j} {        append txt " & •"    }    return $txt}proc tabular {} {    global promptNoisily useStatusBar    set envName "tabular"    if {$promptNoisily && $useStatusBar} {beep}    catch {sPrompt "$envName:  how many rows?" 3} numberRows    if {$numberRows != "cancel"} then {        if {$promptNoisily && $useStatusBar} {beep}        catch {sPrompt "$envName:  how many columns?" 3} numberCols        if {$numberCols != "cancel"} then {            set arg "{|"            for {set j 1} {$j <= $numberCols} {incr j} {                append arg "c|"            }            append arg "}"            set body "\t\\hline\r"            for {set i 1} {$i <= $numberRows} {incr i} {                append body "\t[buildRow $numberCols]"                append body "  \\\\\r\t\\hline\r"            }            if {[insertEnvironment $envName $arg $body]} then {                nextTabStop                message "type first item"            }        }    }}proc verbatim {} { doWrapEnvironment "verbatim" }proc quote {} { doWrapEnvironment "quote" }proc quotation {} { doWrapEnvironment "quotation" }proc verse {} { doWrapEnvironment "verse" }proc flushleft {} { doWrapEnvironment "flushleft" }proc center {} { doWrapEnvironment "center" }proc flushright {} { doWrapEnvironment "flushright" }proc general {} {    catch {prompt "What environment?" "center"} environmentName    if {$environmentName != "cancel"} {        doWrapEnvironment "$environmentName"    }}#--------------------------------------------------------------------------# Boxes:#--------------------------------------------------------------------------proc mbox {} {    if {[wrapObject "\\mbox{" "}•"]} then {        message "mbox set"    } else {        message "enter text"    }}proc makebox {} {    if {[wrapObject "\\makebox\[•\]\[•\]{" "}•"]} then {        message "makebox set; enter the width and position"    } else {        message "enter the width and position of the makebox, then the text"    }}proc fbox {} {    if {[wrapObject "\\fbox{" "}•"]} then {        message "fbox set"    } else {        message "enter text"    }}proc framebox {} {    if {[wrapObject "\\framebox\[•\]\[•\]{" "}•"]} then {        message "framebox set; enter the width and position"    } else {        message "enter the width and position of the framebox, then the text"    }}proc newsavebox {} {    if {[wrapObject "\\newsavebox{" "}•"]} then {        message "newsavebox defined"    } else {        message "enter the command name of the sbox or savebox"    }}proc sbox {} {    if {[wrapObject "\\sbox{•}{" "}•"]} then {        message "sbox set; enter the command name"    } else {        message "enter the command name of the sbox, then the text"    }}proc savebox {} {    if {[wrapObject "\\savebox{•}\[•\]\[•\]{" "}•"]} then {        message "savebox set; enter the command name"    } else {        message "enter the command name of the savebox"    }}proc usebox {} {    if {[wrapObject "\\usebox{" "}•"]} then {        message "usebox declared"    } else {        message "enter the command name of the sbox or savebox"    }}proc raisebox {} {    if {[wrapObject "\\raisebox{•}\[•\]\[•\]{" "}•"]} then {        message "raisebox set; enter the displacement"    } else {        message "enter the displacement of the raisebox"    }}proc parbox {} {    if {[wrapObject "\\parbox\[•\]\{•\}{" "}•"]} then {        message "parbox set; enter the position and width"    } else {        message "enter the position and width of the parbox, then the text"    }}proc minipage {} {    set arg "\[•\]{•}"    wrapEnvironment "minipage" $arg ""    nextTabStop    message "enter the position of the minipage, then the width"}proc rule {} {    insertObject "\\rule\[•\]\{•\}{•}•"    nthTabStop -4    message "enter the displacement of the rule, then width and height"}#--------------------------------------------------------------------------# Misc:#--------------------------------------------------------------------------proc ldots {} {insertObject "\\ldots"}proc {en-dash} {} {insertObject "--"}proc {em-dash} {} {insertObject "---"}proc texLogo {} {insertObject "\\TeX"}proc latexLogo {} {insertObject "\\LaTeX"}proc latex2eLogo {} {insertObject "\\LaTeXe"}proc today {} {insertObject "\\today"}proc dag {} {insertObject "\\dag"}proc ddag {} {insertObject "\\ddag"}proc sectionMark {} {insertObject "\\S"}proc paragraphMark {} {insertObject "\\P"}proc copyright {} {insertObject "\\copyright"}proc pounds {} {insertObject "\\pounds"}proc quotes {} {    if {[wrapObject "`" "'•"]} then {        message "text quoted"    } else {        message "enter text"    }}proc dblQuotes {} {    if {[wrapObject "``" "''•"]} then {        message "text double quoted"    } else {        message "enter text"    }}proc marginalNote {} {    if {[wrapObject "\\marginpar{" "}•"]} then {        message "marginal note set"    } else {        message "enter marginal note"    }}proc footnote {} {    if {[wrapObject "\\footnote{" "}•"]} then {        message "footnote set"    } else {        message "enter footnote"    }}proc label {} {    if {[wrapObject "\\label{" "}•"]} then {        message "label defined"    } else {        message "enter label"    }}proc ref {} {     if {[wrapObject "\\ref{" "}•"]} then {        message "cross-reference made"    } else {        message "enter cross-reference"    }}proc pageref {} {     if {[wrapObject "\\pageref{" "}•"]} then {        message "page reference made"    } else {        message "enter page reference"    }}proc cite {} {    if {[wrapObject "\\cite{" "}•"]} then {        message "citation made"    } else {        message "enter citation"    }}proc item {} {insertObject "\\item"}proc bibitem {} {    if {[wrapObject "\\bibitem{" "}•"]} then {        message "bibitem set"    } else {        message "enter bibitem"    }}############################################################################## # Math Mode Macros###############################################################################--------------------------------------------------------------------------# Math Modes:#--------------------------------------------------------------------------proc texMath {} {    if {[wrapObject "$" "$•"]} then {        message "formula set"    } else {        message "enter formula"    }}proc texDisplaymath {} {    if {[wrapObject "$$" "$$•"]} then {        message "displayed formula set"    } else {        message "enter displayed formula"    }}proc latexMath {} {    if {[wrapObject "\\( " " \\)•"]} then {        message "formula set"    } else {        message "enter formula"    }}proc latexDisplaymath {} {    if {[wrapObject "\\\[ " " \\\]•"]} then {        message "displayed formula set"    } else {        message "enter displayed formula"    }}#--------------------------------------------------------------------------# Math Style:#--------------------------------------------------------------------------proc mathit {} {    if {[wrapObject "\\mathit{" "}•"]} then {        message "selected text is math italic"    } else {        message "enter text to be math italic"    }}proc mathrm {} {    if {[wrapObject "\\mathrm{" "}•"]} then {        message "selected text is math roman"    } else {        message "enter text to be math roman"    }}proc mathbf {} {    if {[wrapObject "\\mathbf{" "}•"]} then {        message "selected text is math bold"    } else {        message "enter text to be math bold"    }}proc mathsf {} {    if {[wrapObject "\\mathsf{" "}•"]} then {        message "selected text is math sans serif"    } else {        message "enter text to be math sans serif"    }}proc mathtt {} {    if {[wrapObject "\\mathtt{" "}•"]} then {        message "selected text is math typewriter"    } else {        message "enter text to be math typewriter"    }}proc mathcal {} {    # Allow upper-case arguments only:    if {[isSelection] && ![isUppercase]} then {        alertnote "argument to \\mathcal must be uppercase"        return    }    if {[wrapObject "\\mathcal{" "}•"]} then {        message "selected text is calligraphic"    } else {        message "enter text to be calligraphic (UPPERCASE letters only)"    }}proc displaystyle {} {    if {[wrapObject "{\\displaystyle " "}•"]} then {        message "displaystyle set"    } else {        message "enter displaystyle text"    }}proc textstyle {} {    if {[wrapObject "{\\textstyle " "}•"]} then {        message "textstyle set"    } else {        message "enter textstyle text"    }}proc scriptstyle {} {    if {[wrapObject "{\\scriptstyle " "}•"]} then {        message "scriptstyle set"    } else {        message "enter scriptstyle text"    }}proc scriptscriptstyle {} {    if {[wrapObject "{\\scriptscriptstyle " "}•"]} then {        message "scriptscriptstyle set"    } else {        message "enter scriptscriptstyle text"    }}#--------------------------------------------------------------------------# Math Environments:#--------------------------------------------------------------------------proc math {} { doWrapEnvironment "math" }proc displaymath {} { doWrapEnvironment "displaymath" }proc equation {} {    set envName "equation"    set body "\t\\label{•}\r"    if {[wrapEnvironment $envName "" $body]} then {        set msgText "equation wrapped"    } else {        set msgText "enter equation"    }    nextTabStop    message $msgText}proc myArray {} {    global promptNoisily useStatusBar    set envName "array"    if {$promptNoisily && $useStatusBar} {beep}    catch {sPrompt "$envName:  how many rows?" 3} numberRows    if {$numberRows != "cancel"} then {        if {$promptNoisily && $useStatusBar} {beep}        catch {sPrompt "$envName:  how many columns?" 3} numberCols        if {$numberCols != "cancel"} then {            set arg "{"            for {set j 1} {$j <= $numberCols} {incr j} {                append arg "c"            }            append arg "}"            set row "\t[buildRow $numberCols]"            for {set i 1} {$i < $numberRows} {incr i} {                append body $row                append body "  \\\\\r\t\r"            }            append body $row            append body "\r"            if {[insertEnvironment $envName $arg $body]} then {                nextTabStop                message "type first item"            }        }    }}proc eqnarrayStar {} {    global promptNoisily useStatusBar    set envName "eqnarray*"    if {$promptNoisily && $useStatusBar} {beep}    catch {sPrompt "$envName:  how many rows?" 3} numberRows    if {$numberRows != "cancel"} then {        set row "\t[buildRow 3]"        for {set i 1} {$i < $numberRows} {incr i} {            append body $row            append body "  \\\\\r"        }        append body $row        append body "\r"        if {[insertEnvironment $envName "" $body]} then {            nextTabStop            message "type first item"        }    }}proc eqnarray {} {    global promptNoisily useStatusBar    set envName "eqnarray"    if {$promptNoisily && $useStatusBar} {beep}    catch {sPrompt "$envName:  how many rows?" 3} numberRows    if {$numberRows != "cancel"} then {        set row "\t[buildRow 3]\r\t\\label{•}"        for {set i 1} {$i < $numberRows} {incr i} {            append body $row            append body "  \\\\\r"        }        append body $row        append body "\r"        if {[insertEnvironment $envName "" $body]} then {            nextTabStop            message "type first item"        }    }}#--------------------------------------------------------------------------# Formulas:#--------------------------------------------------------------------------proc subscript {} {    if {[wrapObject "_{" "}•"]} then {        message "subscript set"    } else {        message "enter subscript"    }}proc superscript {} {    if {[wrapObject "^{" "}•"]} then {        message "superscript set"    } else {        message "enter superscript"    }}proc fraction {} {    set currentPos [getPos]    if {[isSelection]} then {        set selection [getSelect]        set args [split $selection /]        set len [llength $args]        deleteText $currentPos [selEnd]        if {$len == 1} then {            insertText "\\frac{" $selection "}{•}•"            goto $currentPos            nextTabStop            message "enter denominator"        } else {            set firstArg [lindex $args 0]            set restArgs [lrange $args 1 [expr $len-1]]            insertText "\\frac{" $firstArg "}{" [join $restArgs /] "}"            if {$len > 2} {message "beware of multiple /"}        }    } else {        insertText "\\frac{•}{•}•"        goto $currentPos        nextTabStop        message "enter numerator"    }}proc squareRoot {} {    if {[wrapObject "\\sqrt{" "}•"]} then {        message "square root set"    } else {        message "enter formula"    }}proc nthRoot {} {    if {[wrapObject "\\sqrt\[•\]{" "}•"]} then {        message "enter root"    } else {        message "enter root, then formula"    }}proc oneParameter {} {    catch {prompt "Command name?" "sqrt"} commandName    if {$commandName != "cancel"} {wrapObject "\\$commandName{" "}•"}}proc twoParameters {} {    catch {prompt "Command name?" "frac"} commandName    if {$commandName != "cancel"} then {        set currentPos [getPos]        if {[insertObject "\\$commandName{•}{•}•"]} then {            goto $currentPos            nextTabStop        }    }}#--------------------------------------------------------------------------# Greek:#--------------------------------------------------------------------------proc alpha {} {insertObject "\\alpha"}proc beta {} {insertObject "\\beta"}proc gamma {} {insertObject "\\gamma"}proc delta {} {insertObject "\\delta"}proc epsilon {} {insertObject "\\epsilon"}proc zeta {} {insertObject "\\zeta"}proc eta {} {insertObject "\\eta"}proc theta {} {insertObject "\\theta"}proc iota {} {insertObject "\\iota"}proc kappa {} {insertObject "\\kappa"}proc lambda {} {insertObject "\\lambda"}proc mu {} {insertObject "\\mu"}proc nu {} {insertObject "\\nu"}proc xi {} {insertObject "\\xi"}proc omicron {} {insertObject "o"}proc pi {} {insertObject "\\pi"}proc rho {} {insertObject "\\rho"}proc sigma {} {insertObject "\\sigma"}proc tau {} {insertObject "\\tau"}proc upsilon {} {insertObject "\\upsilon"}proc phi {} {insertObject "\\phi"}proc chi {} {insertObject "\\chi"}proc psi {} {insertObject "\\psi"}proc omega {} {insertObject "\\omega"}proc Gamma {} {insertObject "\\Gamma"}proc Delta {} {insertObject "\\Delta"}proc Theta {} {insertObject "\\Theta"}proc Lambda {} {insertObject "\\Lambda"}proc Xi {} {insertObject "\\Xi"}proc Pi {} {insertObject "\\Pi"}proc Sigma {} {insertObject "\\Sigma"}proc Upsilon {} {insertObject "\\Upsilon"}proc Phi {} {insertObject "\\Phi"}proc Psi {} {insertObject "\\Psi"}proc Omega {} {insertObject "\\Omega"}proc varepsilon {} {insertObject "\\varepsilon"}proc vartheta {} {insertObject "\\vartheta"}proc varpi {} {insertObject "\\varpi"}proc varrho {} {insertObject "\\varrho"}proc varsigma {} {insertObject "\\varsigma"}proc varphi {} {insertObject "\\varphi"}#--------------------------------------------------------------------------# Binary Ops:#--------------------------------------------------------------------------proc pm {} {insertObject "\\pm"}proc mp {} {insertObject "\\mp"}proc times {} {insertObject "\\times"}proc div {} {insertObject "\\div"}proc ast {} {insertObject "\\ast"}proc star {} {insertObject "\\star"}proc circ {} {insertObject "\\circ"}proc bullet {} {insertObject "\\bullet"}proc cdot {} {insertObject "\\cdot"}proc cap {} {insertObject "\\cap"}proc cup {} {insertObject "\\cup"}proc uplus {} {insertObject "\\uplus"}proc sqcap {} {insertObject "\\sqcap"}proc sqcup {} {insertObject "\\sqcup"}proc vee {} {insertObject "\\vee"}proc wedge {} {insertObject "\\wedge"}proc setminus {} {insertObject "\\setminus"}proc wr {} {insertObject "\\wr"}proc diamond {} {insertObject "\\diamond"}proc bigtriangleup {} {insertObject "\\bigtriangleup"}proc bigtriangledown {} {insertObject "\\bigtriangledown"}proc triangleleft {} {insertObject "\\triangleleft"}proc triangleright {} {insertObject "\\triangleright"}proc lhd {} { if {[isSymbolPackageLoaded]} then {insertObject "\\lhd"} }proc rhd {} { if {[isSymbolPackageLoaded]} then {insertObject "\\rhd"} }proc unlhd {} { if {[isSymbolPackageLoaded]} then {insertObject "\\unlhd"} }proc unrhd {} { if {[isSymbolPackageLoaded]} then {insertObject "\\unrhd"} }proc oplus {} {insertObject "\\oplus"}proc ominus {} {insertObject "\\ominus"}proc otimes {} {insertObject "\\otimes"}proc oslash {} {insertObject "\\oslash"}proc odot {} {insertObject "\\odot"}proc bigcirc {} {insertObject "\\bigcirc"}proc dagger {} {insertObject "\\dagger"}proc ddagger {} {insertObject "\\ddagger"}proc amalg {} {insertObject "\\amalg"}#--------------------------------------------------------------------------# Relations:#--------------------------------------------------------------------------proc leq {} {insertObject "\\leq"}proc prec {} {insertObject "\\prec"}proc preceq {} {insertObject "\\preceq"}proc myLl {} {insertObject "\\ll"}proc subset {} {insertObject "\\subset"}proc subseteq {} {insertObject "\\subseteq"}proc sqsubset {} {    if {[isSymbolPackageLoaded]} then {insertObject "\\sqsubset"}}proc sqsubseteq {} {insertObject "\\sqsubseteq"}proc in {} {insertObject "\\in"}proc vdash {} {insertObject "\\vdash"}proc geq {} {insertObject "\\geq"}proc succ {} {insertObject "\\succ"}proc succeq {} {insertObject "\\succeq"}proc gg {} {insertObject "\\gg"}proc supset {} {insertObject "\\supset"}proc supseteq {} {insertObject "\\supseteq"}proc sqsupset {} {    if {[isSymbolPackageLoaded]} then {insertObject "\\sqsupset"}}proc sqsupseteq {} {insertObject "\\sqsupseteq"}proc ni {} {insertObject "\\ni"}proc dashv {} {insertObject "\\dashv"}proc equiv {} {insertObject "\\equiv"}proc sim {} {insertObject "\\sim"}proc simeq {} {insertObject "\\simeq"}proc asymp {} {insertObject "\\asymp"}proc approx {} {insertObject "\\approx"}proc cong {} {insertObject "\\cong"}proc neq {} {insertObject "\\neq"}proc doteq {} {insertObject "\\doteq"}proc propto {} {insertObject "\\propto"}proc models {} {insertObject "\\models"}proc perp {} {insertObject "\\perp"}proc mid {} {insertObject "\\mid"}proc parallel {} {insertObject "\\parallel"}proc bowtie {} {insertObject "\\bowtie"}proc myJoin {} { if {[isSymbolPackageLoaded]} then {insertObject "\\join"} }proc smile {} {insertObject "\\smile"}proc frown {} {insertObject "\\frown"}#--------------------------------------------------------------------------# Arrows:#--------------------------------------------------------------------------proc leftarrow {} {insertObject "\\leftarrow"}proc Leftarrow {} {insertObject "\\Leftarrow"}proc rightarrow {} {insertObject "\\rightarrow"}proc Rightarrow {} {insertObject "\\Rightarrow"}proc leftrightarrow {} {insertObject "\\leftrightarrow"}proc Leftrightarrow {} {insertObject "\\Leftrightarrow"}proc mapsto {} {insertObject "\\mapsto"}proc hookleftarrow {} {insertObject "\\hookleftarrow"}proc leftharpoonup {} {insertObject "\\leftharpoonup"}proc leftharpoondown {} {insertObject "\\leftharpoondown"}proc rightleftharpoons {} {insertObject "\\rightleftharpoons"}proc longleftarrow {} {insertObject "\\longleftarrow"}proc Longleftarrow {} {insertObject "\\Longleftarrow"}proc longrightarrow {} {insertObject "\\longrightarrow"}proc Longrightarrow {} {insertObject "\\Longrightarrow"}proc longleftrightarrow {} {insertObject "\\longleftrightarrow"}proc Longleftrightarrow {} {insertObject "\\Longleftrightarrow"}proc longmapsto {} {insertObject "\\longmapsto"}proc hookrightarrow {} {insertObject "\\hookrightarrow"}proc rightharpoonup {} {insertObject "\\rightharpoonup"}proc rightharpoondown {} {insertObject "\\rightharpoondown"}proc leadsto {} {    if {[isSymbolPackageLoaded]} then {insertObject "\\leadsto"}}proc uparrow {} {insertObject "\\uparrow"}proc Uparrow {} {insertObject "\\Uparrow"}proc downarrow {} {insertObject "\\downarrow"}proc Downarrow {} {insertObject "\\Downarrow"}proc updownarrow {} {insertObject "\\updownarrow"}proc Updownarrow {} {insertObject "\\Updownarrow"}proc nearrow {} {insertObject "\\nearrow"}proc searrow {} {insertObject "\\searrow"}proc swarrow {} {insertObject "\\swarrow"}proc nwarrow {} {insertObject "\\nwarrow"}#--------------------------------------------------------------------------# Dots:#--------------------------------------------------------------------------proc cdots {} {insertObject "\\cdots"}proc vdots {} {insertObject "\\vdots"}proc ddots {} {insertObject "\\ddots"}#--------------------------------------------------------------------------# Symbols:#--------------------------------------------------------------------------proc aleph {} {insertObject "\\aleph"}proc hbar {} {insertObject "\\hbar"}proc imath {} {insertObject "\\imath"}proc jmath {} {insertObject "\\jmath"}proc ell {} {insertObject "\\ell"}proc wp {} {insertObject "\\wp"}proc Re {} {insertObject "\\Re"}proc Im {} {insertObject "\\Im"}proc mho {} { if {[isSymbolPackageLoaded]} then {insertObject "\\mho"} }proc prime {} {insertObject "\\prime"}proc emptyset {} {insertObject "\\emptyset"}proc nabla {} {insertObject "\\nabla"}proc surd {} {insertObject "\\surd"}proc top {} {insertObject "\\top"}proc bot {} {insertObject "\\bot"}# proc | {} {insertObject "\\|"}proc angle {} {insertObject "\\angle"}proc forall {} {insertObject "\\forall"}proc exists {} {insertObject "\\exists"}proc neg {} {insertObject "\\neg"}proc flat {} {insertObject "\\flat"}proc natural {} {insertObject "\\natural"}proc sharp {} {insertObject "\\sharp"}proc backslash {} {insertObject "\\backslash"}proc partial {} {insertObject "\\partial"}proc infty {} {insertObject "\\infty"}proc Box {} { if {[isSymbolPackageLoaded]} then {insertObject "\\Box"} }proc Diamond {} {    if {[isSymbolPackageLoaded]} then {insertObject "\\Diamond"}}proc triangle {} {insertObject "\\triangle"}proc clubsuit {} {insertObject "\\clubsuit"}proc diamondsuit {} {insertObject "\\diamondsuit"}proc heartsuit {} {insertObject "\\heartsuit"}proc spadesuit {} {insertObject "\\spadesuit"}#--------------------------------------------------------------------------# Functions:#--------------------------------------------------------------------------proc arccos {} {insertObject "\\arccos"}proc arcsin {} {insertObject "\\arcsin"}proc arctan {} {insertObject "\\arctan"}proc arg {} {insertObject "\\arg"}proc cos {} {insertObject "\\cos"}proc cosh {} {insertObject "\\cosh"}proc cot {} {insertObject "\\cot"}proc coth {} {insertObject "\\coth"}proc csc {} {insertObject "\\csc"}proc deg {} {insertObject "\\deg"}proc det {} {insertObject "\\det"}proc dim {} {insertObject "\\dim"}proc exp {} {insertObject "\\exp"}proc gcd {} {insertObject "\\gcd"}proc hom {} {insertObject "\\hom"}proc inf {} {insertObject "\\inf"}proc ker {} {insertObject "\\ker"}proc lg {} {insertObject "\\lg"}proc lim {} {insertObject "\\lim"}proc liminf {} {insertObject "\\liminf"}proc limsup {} {insertObject "\\limsup"}proc ln {} {insertObject "\\ln"}proc log {} {insertObject "\\log"}proc max {} {insertObject "\\max"}proc min {} {insertObject "\\min"}proc Pr {} {insertObject "\\Pr"}proc sec {} {insertObject "\\sec"}proc sin {} {insertObject "\\sin"}proc sinh {} {insertObject "\\sinh"}proc sup {} {insertObject "\\sup"}proc tan {} {insertObject "\\tan"}proc tanh {} {insertObject "\\tanh"}proc bmod {} {insertObject "\\bmod"}proc pmod {} {    if {[wrapObject "\\pmod{" "}•"]} then {        message "parenthesized mod set"    } else {        message "enter formula"    }}#--------------------------------------------------------------------------# Large Ops:#--------------------------------------------------------------------------proc insertLargeOp {commandName} {    set currentPos [getPos]    insertText "\\$commandName"    insertText "_{•}^{•}•"    goto $currentPos    nextTabStop}proc sum {} {insertLargeOp "sum"}proc prod {} {insertLargeOp "prod"}proc coprod {} {insertLargeOp "coprod"}proc int {} {insertLargeOp "int"}proc oint {} {insertLargeOp "oint"}proc bigcap {} {insertLargeOp "bigcap"}proc bigcup {} {insertLargeOp "bigcup"}proc bigsqcap {} {insertLargeOp "bigsqcap"}proc bigsqcup {} {insertLargeOp "bigsqcup"}proc bigvee {} {insertLargeOp "bigvee"}proc bigwedge {} {insertLargeOp "bigwedge"}proc bigodot {} {insertLargeOp "bigodot"}proc bigotimes {} {insertLargeOp "bigotimes"}proc bigoplus {} {insertLargeOp "bigoplus"}proc biguplus {} {insertLargeOp "biguplus"}#--------------------------------------------------------------------------# Delimiters:#--------------------------------------------------------------------------proc delimitObject {leftDelim rightDelim} {    if {[wrapObject $leftDelim $rightDelim]} then {        message "formula delimited"    } else {        message "enter formula"    }}proc parentheses {} { delimitObject "(" ")•" }proc brackets {} { delimitObject "\[" "\]•" }proc braces {} { delimitObject "\\\{" "\\\}•" }proc absoluteValue {} { delimitObject "|" "|•" }proc getDelims {} {    catch {prompt "Choose delimiters:" "parentheses" "" "parentheses" \                  "brackets" "braces" "angle brackets" "vertical bars" \                  "double bars" "ceiling" "floor"} delimType    if {$delimType != "cancel"} then {        case $delimType in {            "parentheses" {                set leftDelim "("                set rightDelim ")"            }            "brackets" {                set leftDelim "\["                set rightDelim "\]"            }            "braces" {                set leftDelim "\\\{"                set rightDelim "\\\}"            }            "{vertical bars}" {                set leftDelim "|"                set rightDelim "|"            }            "{double bars}" {                set leftDelim "\\|"                set rightDelim "\\|"            }            "{angle brackets}" {                set leftDelim "\\langle"                set rightDelim "\\rangle"            }            "ceiling" {                set leftDelim "\\lceil"                set rightDelim "\\rceil"            }            "floor" {                set leftDelim "\\lfloor"                set rightDelim "\\rfloor"            }            default {                alertnote "\"$delimType\" not recognized"                return ""            }        }        return [list $leftDelim $rightDelim]    } else {return ""}}proc otherDelims {} {    set delims [getDelims]    if {$delims != ""} then {        set leftDelim [lindex $delims 0]        set rightDelim [lindex $delims 1]        delimitObject "$leftDelim" "$rightDelim•"    }}proc {half-openInterval} {} { delimitObject "(" "\]•" }proc {half-closedInterval} {} { delimitObject "\[" ")•" }proc bigParentheses {} { delimitObject "\\left(" "\\right)•" }proc bigBrackets {} { delimitObject "\\left\[" "\\right\]•" }proc bigBraces {} { delimitObject "\\left\\\{" "\\right\\\}•" }proc bigAbsoluteValue {} { delimitObject "\\left|" "\\right|•" }proc otherBigDelims {} {    set delims [getDelims]    if {$delims != ""} then {        append leftDelim "\\left" [lindex $delims 0]        append rightDelim "\\right" [lindex $delims 1]        delimitObject "$leftDelim" "$rightDelim•"    }}proc bigLeftBrace {} { delimitObject "\\left\\\{" "\\right.•" }proc otherMixedBigDelims {} {    catch {prompt "Choose LEFT delimiter:" "parenthesis" "" "parenthesis" \                  "bracket" "brace" "vertical bar" "double bar" \                  "angle bracket" "ceiling" "floor" "slash" "backslash" \                  "none"} delimType    if {$delimType != "cancel"} then {        case $delimType in {            "parenthesis" {set leftDelim "("}            "bracket" {set leftDelim "\["}            "brace" {set leftDelim "\\\{"}            "{vertical bar}" {set leftDelim "|"}            "{double bar}" {set leftDelim "\\|"}            "{angle bracket}" {set leftDelim "\\langle"}            "ceiling" {set leftDelim "\\lceil"}            "floor" {set leftDelim "\\lfloor"}            "slash" {set leftDelim "/"}            "backslash" {set leftDelim "\\backslash"}            "none" {set leftDelim "."}            default {                alertnote "\"$delimType\" not recognized"                return            }        }        catch {prompt "Choose RIGHT delimiter:" "parenthesis" "" "parenthesis" \                      "bracket" "brace" "vertical bar" "double bar" \                      "angle bracket" "ceiling" "floor" "slash" "backslash" \                      "none"} delimType        if {$delimType != "cancel"} then {            case $delimType in {                "parenthesis" {set rightDelim ")"}                "bracket" {set rightDelim "\]"}                "brace" {set rightDelim "\\\}"}                "{vertical bar}" {set rightDelim "|"}                "{double bar}" {set rightDelim "\\|"}                "{angle bracket}" {set rightDelim "\\rangle"}                "ceiling" {set rightDelim "\\rceil"}                "floor" {set rightDelim "\\rfloor"}                "slash" {set rightDelim "/"}                "backslash" {set rightDelim "\\backslash"}                "none" {set rightDelim "."}                default {                    alertnote "\"$delimType\" not recognized"                    return                }            }            delimitObject "\\left$leftDelim" "\\right$rightDelim•"        }    }}#--------------------------------------------------------------------------# Accents:#--------------------------------------------------------------------------proc acute {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\acute{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc bar {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\bar{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc breve {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\breve{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc check {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\check{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc dot {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\dot{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc ddot {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\ddot{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc grave {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\grave{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc hat {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\hat{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc tilde {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\tilde{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc vec {} {    if {[isSelection] > 1} then {        alertnote "Warning: only a single character may be accented!"    }    if {[wrapObject "\\vec{" "}•"]} then {        message "accent set"    } else {        message "enter one character"    }}proc widehat {} {    if {[isSelection] > 3} then {        alertnote "Warning: only a few characters may be accented!"    }    if {[wrapObject "\\widehat{" "}•"]} then {        message "accent set"    } else {        message "enter a few characters"    }}proc widetilde {} {    if {[isSelection] > 3} then {        alertnote "Warning: only a few characters may be accented!"    }    if {[wrapObject "\\widetilde{" "}•"]} then {        message "accent set"    } else {        message "enter a few characters"    }}proc imath {} {insertObject "\\imath"}proc jmath {} {insertObject "\\jmath"}#--------------------------------------------------------------------------# Grouping:#--------------------------------------------------------------------------proc underline {} {    if {[wrapObject "\\underline{" "}•"]} then {        message "selection underlined"    } else {        message "enter text"    }}proc overline {} {    if {[wrapObject "\\overline{" "}•"]} then {        message "selection overlined"    } else {        message "enter text"    }}proc underbrace {} {    if {[wrapObject "\\underbrace{" "}•"]} then {        message "selection underbraced"    } else {        message "enter text"    }}proc overbrace {} {    if {[wrapObject "\\overbrace{" "}•"]} then {        message "selection overbraced"    } else {        message "enter text"    }}proc stackrel {} {    set currentPos [getPos]    if {[insertObject "\\stackrel{•}{•}•"]} then {        goto $currentPos        nextTabStop        message "1st arg scriptstyle"    }}#--------------------------------------------------------------------------# Spacing:#--------------------------------------------------------------------------proc negThin {} {insertObject "\\!"}proc thin {} {insertObject "\\,"}proc medium {} {insertObject "\\:"}proc thick {} {insertObject "\\;"}proc quad {} {insertObject "\\quad"}proc qquad {} {insertObject "\\qquad"}proc hspace {} {    if {[wrapObject "\\hspace{" "}•"]} then {        message "spacing set"    } else {        message "enter the desired horizontal spacing"    }}proc vspace {} {    if {[wrapObject "\\vspace{" "}•"]} then {        message "spacing set"    } else {        message "enter the desired horizontal spacing"    }}proc hfill {} {insertObject "\\hfill"}proc vfill {} {insertObject "\\vfill"}proc smallskip {} {insertObject "\\smallskip"}proc medskip {} {insertObject "\\medskip"}proc bigskip {} {insertObject "\\bigskip"}############################################################################### LaTeX Menu Definition## (see file "latexMenu.tcl")##############################################################################source "$HOME:Tcl:SystemCode:latexMenu.tcl"buildLaTeXMenu############################################################################### Special LaTeX Key Bindings## (see file "latexKeys.tcl")##############################################################################source "$HOME:Tcl:SystemCode:latexKeys.tcl"bindLaTeXKeys